import { ref } from 'vue';
import { getPurchaseDetailsApi } from '@/api/sj/purchaseManagement/purchaseOrder/index';
import { getPurchaseAndStorageDetails } from '@/api/sj/purchaseManagement/paperProcurement/index';

const useWarehousingDetails = () => {

    const detailVisible = ref(false);
    const detailRow = ref({});
    const detailList = ref();

    /**
     * @description: 打开采购入库详情
     */
    const handleOpenDetails = async (row: any) => {
        console.log(row);
        const data = await getDetails(row.purchaseInRecordId)
        console.log(data, '12312')
        detailVisible.value = true;
    };

    /**
     * 获取详情数据
     */
    const getDetails = (id: any) => {
        return new Promise(async (resolve, reject) => {
            const { code, data } = await getPurchaseDetailsApi(id);
            if (code == 200) {
                resolve(data)
            }
        });
    };


    /**
     * @package 打开 采购申请单 的 详情
     */
    const handleOpenPurchaseApplyDetails = async (row: any) => {
        detailRow.value = row;
        try {
            const {data} = await getPurchaseAndStorageDetails(row.id);
            console.log(data, '1231231')
            detailList.value = data;
        } catch (error) {
            
        }
        detailVisible.value = true;
    };


    return {
        detailVisible,
        detailRow,
        detailList,
        handleOpenPurchaseApplyDetails,
        handleOpenDetails,
    }
};

export default useWarehousingDetails;